﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex;
using MediaMonitor.Common;
using MediaMonitor.Controls;
using Telerik.Web.UI;
using System.Web.Services;
using System.Collections;

namespace MediaMonitor.Users
{
    public partial class Report_Outdoor_Filter : Adex.BasePage
    {
        ArrayList BillBoardQuantity = new ArrayList();
        ArrayList Carriers = new ArrayList();
        ArrayList BillboardType = new ArrayList();
        ArrayList NegotiatedPrice = new ArrayList();

        ArrayList arrExceptionalCaseAvenueName = new ArrayList();
        ArrayList arrExceptionalCaseAverageVehicle = new ArrayList();
        ArrayList arrExceptionalCaseBillBoardQuant = new ArrayList();
        ArrayList arrExceptionalCaseCarrier = new ArrayList();
        ArrayList arrExceptionalCaseBillBoardType = new ArrayList();
        ArrayList arrExceptionalCaseNegoPrice = new ArrayList();

        ArrayList arrColors = new ArrayList();

        string SelectedMediaCode;
        DateTime sDate = DateTime.MinValue, eDate = DateTime.MinValue;
        private int mediaTypeCode = 0;
        private string mediaCodes = "";
        private int programCode = 0;
        private int sectorCode = 0, subSectorCode = 0, subSector2Code = 0, categoryCode = 0;
        int advertiserCode = 0, brandCode = 0, productCode = 0, versionCode = 0, agencyCode = 0;
        int sTime = 0, eTime = 0;
        int sPrice = 0, ePrice = 0;
        private int typeOfAds = 0;
        private int size = 0;
        private string quality = "";
        bool firstAppearanceOnly = false;
        bool DownloadOnly = false;
        bool DownloadOnlyProduct = false;
        bool DownloadOnlyAdvertiser = false;

        private string sector = "", subsector = "", category = "", advertiser = "", agency = "";
        private string product = "", version = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnSearch1.Text = "Search";
                Session["SelectedAvenuesBillBoardQuant"] = null;
                Session["SelectedAvenuesBillBoardType"] = null;
                Session["SelectedAvenuesCarrier"] = null;
                Session["SelectedNegoPrice"] = null;
                Session["ExceptionalCaseAvenueName"] = null;
                Session["ExceptionalCaseAverageVehicle"] = null;
                Session["ExceptionalCaseBillBoardQuantity"] = null;
                Session["ExceptionalCaseCarrier"] = null;
                Session["ExceptionalCaseBillBoardType"] = null;
                Session["ExceptionalCaseNegoPrice"] = null;

                #region To add different Colors for Avenues
                arrColors.Add("#5D8AA8");
                arrColors.Add("#00308F");
                arrColors.Add("#A32638");
                arrColors.Add("#C46210");
                arrColors.Add("#E52B50");
                arrColors.Add("#3B7A57");
                arrColors.Add("#FFBF00");
                arrColors.Add("#9966CC");
                arrColors.Add("#A4C639");
                arrColors.Add("#665D1E");
                arrColors.Add("#008000");
                arrColors.Add("#00FFFF");
                arrColors.Add("#FDEE00");
                arrColors.Add("#007FFF");
                arrColors.Add("#89CFF0");
                arrColors.Add("#F4C2C2");
                arrColors.Add("#21ABCD");
                arrColors.Add("#98777B");
                arrColors.Add("#BCD4E6");
                arrColors.Add("#2E5894");
                arrColors.Add("#967117");
                arrColors.Add("#CAE00D");
                arrColors.Add("#FE6F5E");
                arrColors.Add("#3D0C02");
                arrColors.Add("#253529");
                arrColors.Add("#A57164");
                arrColors.Add("#318CE7");
                arrColors.Add("#ACE5EE");
                arrColors.Add("#1F75FE");
                arrColors.Add("#0093AF");
                arrColors.Add("#0087BD");
                arrColors.Add("#333399");
                arrColors.Add("#0247FE");
                arrColors.Add("#A2A2D0");
                arrColors.Add("#6699CC");
                arrColors.Add("#0D98BA");
                arrColors.Add("#126180");
                arrColors.Add("#8A2BE2");
                arrColors.Add("#4F86F7");
                arrColors.Add("#1C1CF0");
                arrColors.Add("#DE5D83");
                arrColors.Add("#79443B");
                arrColors.Add("#0095B6");
                arrColors.Add("#E3DAC9");
                arrColors.Add("#CC0000");
                arrColors.Add("#006A4E");
                arrColors.Add("#873260");
                arrColors.Add("#0070FF");
                arrColors.Add("#B5A642");
                arrColors.Add("#CB4154");
                arrColors.Add("#1DACD6");
                arrColors.Add("#66FF00");
                arrColors.Add("#BF94E4");
                arrColors.Add("#C32148");
                arrColors.Add("#FF007F");
                arrColors.Add("#08E8DE");
                arrColors.Add("#D19FE8");
                arrColors.Add("#F4BBFF");
                arrColors.Add("#FF55A3");
                arrColors.Add("#FB607F");
                arrColors.Add("#004225");
                arrColors.Add("#CD7F32");
                arrColors.Add("#737000");
                arrColors.Add("#964B00");
                arrColors.Add("#A52A2A");
                arrColors.Add("#1B4D3E");
                arrColors.Add("#FFC1CC");
                arrColors.Add("#E7FEFF");
                arrColors.Add("#F0DC82");
                arrColors.Add("#480607");
                arrColors.Add("#800020");
                arrColors.Add("#DEB887");
                arrColors.Add("#CC5500");
                arrColors.Add("#E97451");
                arrColors.Add("#8A3324");
                arrColors.Add("#BD33A4");
                arrColors.Add("#702963");
                arrColors.Add("#536872");
                arrColors.Add("#5F9EA0");
                arrColors.Add("#91A3B0");
                arrColors.Add("#006B3C");
                arrColors.Add("#ED872D");
                arrColors.Add("#E30022");
                arrColors.Add("#FFF600");
                arrColors.Add("#A67B5B");
                arrColors.Add("#4B3621");
                arrColors.Add("#1E4D2B");
                arrColors.Add("#A3C1AD");
                arrColors.Add("#C19A6B");
                arrColors.Add("#EFBBCC");
                arrColors.Add("#78866B");
                arrColors.Add("#FFEF00");
                arrColors.Add("#FF0800");
                arrColors.Add("#E4717A");
                arrColors.Add("#00BFFF");
                arrColors.Add("#592720");
                arrColors.Add("#C41E3A");
                arrColors.Add("#00CC99");
                arrColors.Add("#960018");
                arrColors.Add("#D70040");
                arrColors.Add("#EB4C42");
                arrColors.Add("#FF0038");
                arrColors.Add("#FFA6C9");
                arrColors.Add("#B31B1B");
                arrColors.Add("#99BADD");
                arrColors.Add("#ED9121");
                arrColors.Add("#00563F");
                arrColors.Add("#062A78");
                arrColors.Add("#C95A49");
                arrColors.Add("#92A1CF");
                arrColors.Add("#ACE1AF");
                arrColors.Add("#007BA7");
                arrColors.Add("#2F847C");
                arrColors.Add("#B2FFFF");
                arrColors.Add("#4997D0");
                arrColors.Add("#DE3163");
                arrColors.Add("#EC3B83");
                arrColors.Add("#007BA7");
                arrColors.Add("#2A52BE");
                arrColors.Add("#6D9BC3");
                arrColors.Add("#007AA5");
                arrColors.Add("#E03C31");
                arrColors.Add("#A0785A");
                arrColors.Add("#F7E7CE");
                arrColors.Add("#36454F");
                arrColors.Add("#232B2B");
                arrColors.Add("#E68FAC");
                arrColors.Add("#DFFF00");
                arrColors.Add("#7FFF00");
                arrColors.Add("#DE3163");
                arrColors.Add("#FFB7C5");
                arrColors.Add("#954535");
                arrColors.Add("#DE6FA1");
                arrColors.Add("#A8516E");
                arrColors.Add("#AA381E");
                arrColors.Add("#7B3F00");
                arrColors.Add("#D2691E");
                arrColors.Add("#FFA700");
                arrColors.Add("#98817B");
                arrColors.Add("#E34234");
                arrColors.Add("#D2691E");
                arrColors.Add("#E4D00A");
                arrColors.Add("#9FA91F");
                arrColors.Add("#7F1734");
                arrColors.Add("#FBCCE7");
                arrColors.Add("#0047AB");
                arrColors.Add("#D2691E");
                arrColors.Add("#965A3E");
                arrColors.Add("#6F4E37");
                arrColors.Add("#9BDDFF");
                arrColors.Add("#F88379");
                arrColors.Add("#002E63");
                arrColors.Add("#8C92AC");
                arrColors.Add("#B87333");
                arrColors.Add("#DA8A67");
               ViewState["arrColors"] = arrColors;
                #endregion

                Utility.AddDateControlToPage(this.Page);
                SetCalendarDates();
                //calS.SelectedDate = DateTime.Now.Date;
                //calE.SelectedDate = DateTime.Now.Date;

                FillMediaTypes();
                FillSectors();
                FillSubSectors();
                FillCategories();

                FillAdvertisers();
                FillAgencies();

                lstSize.DataSourceID = "sqlDsSize";
                lstSize.DataTextField = "Size";
                lstSize.DataValueField = "Size";
                lstSize.DataBind();
                lstSize.Items.Insert(0, new ListItem("Any", "0"));

                lstQuality.DataSourceID = "sqlDsQuality";
                lstQuality.DataTextField = "Quality";
                lstQuality.DataValueField = "Quality";
                lstQuality.DataBind();
                lstQuality.Items.Insert(0, new ListItem("Any", ""));

                lstTypeOfAds.DataSourceID = "sqlDsTypeOfAds";
                lstTypeOfAds.DataTextField = "TypeOfAds";
                lstTypeOfAds.DataValueField = "TypeOfAds";
                lstTypeOfAds.DataBind();
                lstTypeOfAds.Items.Insert(0, new ListItem("Any", "0"));

                Session["OUTDOORUserWriteProductName"] = 0;
                Session["OUTDOORVerUserWriteProductName"] = 0;

                Session["OUTDOORUserWriteProductNameText"] = "";
                Session["OUTDOORVerUserWriteProductNameText"] = "";

            }
            if (lstMediaType.SelectedValue == "10") //Planning
            {
                int j = 0;
                DataTable dt = new DataTable(); DataTable dtBillBordsPageLoad = new DataTable();
                foreach (ListItem listitem in lstMedia.Items)
                {

                    if (listitem.Selected)
                    {
                        arrColors = (ArrayList)ViewState["arrColors"];
                        SelectedMediaCode = listitem.Value;
                        dt = RfController.GetPlanning_SelectedMedia(SelectedMediaCode);
                        #region Region to add as many number of Textboxes and Dropdowns as many checkboxes are checked.
                        if (listitem.Text != "AVENIDA NO MONITOREADA POR AGB")
                        {
                            listitem.Attributes.Add("style", "border:1px solid " + arrColors[j] + ";box-shadow:0 0 5px " + arrColors[j] + " inset;");
                            Label lblBillboardsQuantity = new Label();
                            TextBox txtBillboardQuantity = new TextBox();

                            Label lblCarrier = new Label();
                            DropDownList drpMediaCarrier = new DropDownList();

                            Label lblBillboardsType = new Label();
                            DropDownList drpBillBoardsType = new DropDownList();

                            Label lblNegotiatedPrice = new Label();
                            TextBox txtNegotiatedPrice = new TextBox();



                            lblBillboardsQuantity.Text = "Billboards Quantity";
                            lblBillboardsQuantity.Font.Bold = false;
                            lblBillboardsQuantity.ID = "lblBillboardsQuantity" + dt.Rows[0][0].ToString();
                            txtBillboardQuantity.ID = "txtBillboardQuantity" + dt.Rows[0][0].ToString();
                            txtBillboardQuantity.Width = 50;
                            txtBillboardQuantity.ToolTip = "Indique la cantidad de avisos que colocará en esta avenida, en este sentido";
                            txtBillboardQuantity.Style.Add("border", "1px solid " + arrColors[j] + "");
                            txtBillboardQuantity.Style.Add("box-shadow", "0 0 5px " + arrColors[j] + " inset");
                            BillBoardQuantity.Add(txtBillboardQuantity);
                            ViewState["ArrayListBillBoardQuantity"] = BillBoardQuantity;


                            lblCarrier.Text = "Carrier";
                            lblCarrier.Font.Bold = false;
                            lblCarrier.ID = "lblCarrier" + dt.Rows[0][0].ToString();
                            drpMediaCarrier.ID = "drpMediaCarrier" + dt.Rows[0][0].ToString();
                            drpMediaCarrier.Width = 110;
                            drpMediaCarrier.DataTextField = "Carriers";
                            drpMediaCarrier.DataValueField = "Carriers";
                            drpMediaCarrier.AutoPostBack = true;
                            drpMediaCarrier.Style.Add("border", "1px solid " + arrColors[j] + "");
                            drpMediaCarrier.Style.Add("box-shadow", "0 0 5px " + arrColors[j] + " inset");
                            drpMediaCarrier.SelectedIndexChanged += new EventHandler(drpMediaCarrier_SelectedIndexChanged);
                            drpMediaCarrier.DataSource = dt;
                            drpMediaCarrier.DataBind();
                            Carriers.Add(drpMediaCarrier);
                            ViewState["ArrayListCarriers"] = Carriers;


                            lblBillboardsType.Text = "Billboards Type";
                            lblBillboardsType.ID = "lblBillboardsType" + dt.Rows[0][0].ToString();
                            lblBillboardsType.Font.Bold = false;
                            drpBillBoardsType.ID = "drpBillBoardsType" + dt.Rows[0][0].ToString();
                            drpBillBoardsType.Width = 110;
                            dtBillBordsPageLoad = RfController.GetPlanning_SelectedBillBordsTypeOfCarriers(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString());
                            drpBillBoardsType.DataTextField = "BillboardType";
                            drpBillBoardsType.DataValueField = "BillboardType";
                            drpBillBoardsType.Style.Add("border", "1px solid " + arrColors[j] + "");
                            drpBillBoardsType.Style.Add("box-shadow", "0 0 5px " + arrColors[j] + " inset");
                            drpBillBoardsType.DataSource = dtBillBordsPageLoad;
                            drpBillBoardsType.DataBind();
                            BillboardType.Add(drpBillBoardsType);
                            ViewState["ArrayListBillboardType"] = BillboardType;


                            lblNegotiatedPrice.Text = "Negotiated Price ($)";
                            lblNegotiatedPrice.Font.Bold = false;
                            txtNegotiatedPrice.ID = "txtNegotiatedPrice" + dt.Rows[0][0].ToString();
                            txtNegotiatedPrice.Width = 50;
                            txtNegotiatedPrice.ToolTip = "Indique el Monto negociado para los anuncios";
                            txtNegotiatedPrice.Style.Add("border", "1px solid " + arrColors[j] + "");
                            txtNegotiatedPrice.Style.Add("box-shadow", "0 0 5px " + arrColors[j] + " inset");
                            NegotiatedPrice.Add(txtNegotiatedPrice);
                            ViewState["ArrayListNegotiatedPrice"] = NegotiatedPrice;

                            PanelRandomCntrolsHolder.Controls.Add(lblBillboardsQuantity);
                            PanelRandomCntrolsHolder.Controls.Add(txtBillboardQuantity);
                            PanelRandomCntrolsHolder.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));

                            PanelRandomCntrolsHolder.Controls.Add(lblCarrier);
                            PanelRandomCntrolsHolder.Controls.Add(drpMediaCarrier);
                            PanelRandomCntrolsHolder.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));


                            PanelRandomCntrolsHolder.Controls.Add(lblBillboardsType);
                            PanelRandomCntrolsHolder.Controls.Add(drpBillBoardsType);

                            PanelRandomCntrolsHolder.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
                            PanelRandomCntrolsHolder.Controls.Add(lblNegotiatedPrice);
                            PanelRandomCntrolsHolder.Controls.Add(txtNegotiatedPrice);

                            // Add a spacer in the form of an HTML <br /> element.
                            PanelRandomCntrolsHolder.Controls.Add(new LiteralControl("<br />"));
                            pnlTest.Visible = false;

                            j++;
                        }
                        #endregion

                        #region Region for adding textboxes for only one Exceptional Case.i.e., for "AVENIDA NO MONITOREADA POR AGB"
                        if (listitem.Text == "AVENIDA NO MONITOREADA POR AGB")
                        {
                            listitem.Attributes.Add("style", "border:1px solid black;box-shadow:0 0 5px black inset;");
                            int NumberOfRows = Convert.ToInt32(drpAvenueCOunt.SelectedValue.ToString());
                            for (int i = 0; i < NumberOfRows; i++)
                            {

                                Label lblAvenueNameExc = new Label();
                                TextBox txtAvenueName = new TextBox();

                                lblAvenueNameExc.Text = "Avenue Name";
                                lblAvenueNameExc.Font.Bold = false;
                                lblAvenueNameExc.ID = "lblAvenueNameExc" + dt.Rows[0][0].ToString() + i.ToString();
                                txtAvenueName.ID = "txtAvenueName" + dt.Rows[0][0].ToString() + i.ToString();
                                txtAvenueName.Width = 265;
                                txtAvenueName.Font.Bold = false;
                                txtAvenueName.ToolTip = "Indique el nombre de la avenida donde colocará el aviso, indique también el sentido.";
                                arrExceptionalCaseAvenueName.Add(txtAvenueName);
                                ViewState["arrExceptionalCaseAvenueName"] = arrExceptionalCaseAvenueName;

                                Label lblAverageVehicleExc = new Label();
                                TextBox txtAverageVehicle = new TextBox();
                                lblAverageVehicleExc.Text = "Average Vehicle";
                                lblAverageVehicleExc.Font.Bold = false;
                                lblAverageVehicleExc.ID = "lblAverageVehicleExc" + dt.Rows[0][0].ToString() + i.ToString();
                                txtAverageVehicle.ID = "txtAverageVehicle" + dt.Rows[0][0].ToString() + i.ToString();
                                txtAverageVehicle.Width = 50;
                                txtAverageVehicle.ToolTip = "Indique la cantidad de vehículos promedio que pasa diariamente por esa avenida";
                                arrExceptionalCaseAverageVehicle.Add(txtAverageVehicle);
                                ViewState["arrExceptionalCaseAverageVehicle"] = arrExceptionalCaseAverageVehicle;


                                Label lblBillBoardQuantExc = new Label();
                                lblBillBoardQuantExc.Text = "Billboards Quantity";
                                lblBillBoardQuantExc.Font.Bold = false;
                                lblBillBoardQuantExc.ID = "lblBillBoardQuantExc" + dt.Rows[0][0].ToString() + i.ToString();
                                TextBox txtBillBoardQuantExc = new TextBox();
                                txtBillBoardQuantExc.ID = "txtBillBoardQuantExc" + dt.Rows[0][0].ToString() + i.ToString();
                                txtBillBoardQuantExc.Width = 50;
                                txtBillBoardQuantExc.ToolTip = "Indique la cantidad de avisos que colocará en esta avenida, en este sentido";
                                arrExceptionalCaseBillBoardQuant.Add(txtBillBoardQuantExc);
                                ViewState["arrExceptionalCaseBillBoardQuant"] = arrExceptionalCaseBillBoardQuant;


                                Label lblCarrierExc = new Label();
                                lblCarrierExc.Text = "Carrier";
                                lblCarrierExc.Font.Bold = false;
                                lblCarrierExc.ID = "lblCarrierExc" + dt.Rows[0][0].ToString() + i.ToString();
                                TextBox txtCarrier = new TextBox();
                                txtCarrier.ID = "txtCarrier" + dt.Rows[0][0].ToString() + i.ToString();
                                txtCarrier.Width = 100;
                                txtCarrier.ToolTip = "Coloque el nombre de la empresa responsable de colocar y mantener los avisos";
                                arrExceptionalCaseCarrier.Add(txtCarrier);
                                ViewState["arrExceptionalCaseCarrier"] = arrExceptionalCaseCarrier;

                                Label lblBillBoardTypeExc = new Label();
                                lblBillBoardTypeExc.Text = "Billboards Type";
                                lblBillBoardTypeExc.Font.Bold = false;
                                lblBillBoardTypeExc.ID = "lblBillBoardTypeExc" + dt.Rows[0][0].ToString() + i.ToString();
                                TextBox txtBillBoardType = new TextBox();
                                txtBillBoardType.ID = "txtBillBoardType" + dt.Rows[0][0].ToString() + i.ToString();
                                txtBillBoardType.Width = 100; ;
                                txtBillBoardType.ToolTip = "Indique que tipo de aviso colocará";
                                arrExceptionalCaseBillBoardType.Add(txtBillBoardType);
                                ViewState["arrExceptionalCaseBillBoardType"] = arrExceptionalCaseBillBoardType;


                                Label lblNegotiatedPriceExc = new Label();
                                lblNegotiatedPriceExc.Text = "Negotiated Price ($)";
                                lblNegotiatedPriceExc.Font.Bold = false;
                                lblNegotiatedPriceExc.ID = "lblNegotiatedPriceExc" + dt.Rows[0][0].ToString() + i.ToString();
                                TextBox txtNegoPriceExc = new TextBox();
                                txtNegoPriceExc.ID = "txtNegoPriceExc" + dt.Rows[0][0].ToString() + i.ToString();
                                txtNegoPriceExc.Width = 50;
                                txtNegoPriceExc.ToolTip = "Indique el Monto negociado para los anuncios";
                                arrExceptionalCaseNegoPrice.Add(txtNegoPriceExc);
                                ViewState["arrExceptionalCaseNegoPrice"] = arrExceptionalCaseNegoPrice;


                                pnlTest.Controls.Add(lblAvenueNameExc);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));
                                pnlTest.Controls.Add(txtAvenueName);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));

                                pnlTest.Controls.Add(lblAverageVehicleExc);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));
                                pnlTest.Controls.Add(txtAverageVehicle);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));

                                pnlTest.Controls.Add(lblBillBoardQuantExc);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));
                                pnlTest.Controls.Add(txtBillBoardQuantExc);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));

                                pnlTest.Controls.Add(lblCarrierExc);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));
                                pnlTest.Controls.Add(txtCarrier);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));


                                pnlTest.Controls.Add(lblBillBoardTypeExc);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));
                                pnlTest.Controls.Add(txtBillBoardType);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));

                                pnlTest.Controls.Add(lblNegotiatedPriceExc);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));
                                pnlTest.Controls.Add(txtNegoPriceExc);
                                pnlTest.Controls.Add(new LiteralControl("&nbsp;"));

                                pnlTest.Controls.Add(new LiteralControl("<br />"));
                                pnlTest.Controls.Add(new LiteralControl("<hr />"));
                                pnlTest.Controls.Add(new LiteralControl("<br />"));
                                pnlTest.Style.Add("border", "1px solid black");
                                pnlTest.Style.Add("box-shadow", "0 0 5px black inset");
                                pnlTest.GroupingText = "****AVENIDA NO MONITOREADA POR AGB****";
                                pnlTest.Font.Bold = true;
                                pnlTest.Visible = true;

                            }
                        }
                        #endregion

                    }
                    else
                        pnlTest.Visible = false;
                }
            }
        }

        void drpMediaCarrier_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dtBillBords = new DataTable();
            ArrayList arrFetchCarriers = (ArrayList)ViewState["ArrayListCarriers"];
            ArrayList arrFetchBillboards = (ArrayList)ViewState["ArrayListBillboardType"];

            int indexOfSender = 0;
            indexOfSender = arrFetchCarriers.IndexOf(sender);

            DropDownList drpCar = (DropDownList)arrFetchCarriers[indexOfSender];
            string mediaCode = drpCar.ID.Substring(15);
            dtBillBords = RfController.GetPlanning_SelectedBillBordsTypeOfCarriers(mediaCode, drpCar.SelectedValue);

            DropDownList drpBillBoard = (DropDownList)arrFetchBillboards[indexOfSender];
            drpBillBoard.DataTextField = "BillboardType";
            drpBillBoard.DataSource = dtBillBords;
            drpBillBoard.DataBind();


        }

        private void SetCalendarDates()
        {


            DataTable dt = OutdoorLog.Query().DISTINCT().SetSelectList("RFDate").ExecuteDataSet().Tables[0];


            foreach (DataRow dr in dt.Rows)
            {

                RadCalendarDay d1 = new RadCalendarDay(calS);
                d1.Date = Utility.ToDateTime(dr["RFDate"]);
                d1.IsDisabled = false;
                d1.IsSelectable = true;

                d1.ItemStyle.BackColor = System.Drawing.Color.PowderBlue;
                d1.ItemStyle.ForeColor = System.Drawing.Color.White;

                calS.SpecialDays.Add(d1);

                RadCalendarDay d2 = new RadCalendarDay(calE);
                d2.Date = Utility.ToDateTime(dr["RFDate"]);
                d2.IsDisabled = false;
                d2.IsSelectable = true;

                d2.ItemStyle.BackColor = System.Drawing.Color.PowderBlue;
                d2.ItemStyle.ForeColor = System.Drawing.Color.White;


                calE.SpecialDays.Add(d2);
            }



        }

        protected void calS_ViewChanged(object sender, EventArgs e)
        {
            for (DateTime dt = calS.CalendarView.ViewStartDate; dt <= calS.CalendarView.ViewEndDate; dt.AddDays(1))
            {

            }
        }

        private static DataSet GetLookupDataSet()
        {

            if (HttpContext.Current.Cache["dsLookUpByUser_OD_" + AppUser.CurrUserID.ToString()] == null)
            {
                DataSet ds = SPs.GetLookupTables(AppUser.CurrUserID, "OD").GetDataSet();
                ds.Tables[0].TableName = "MediaType";
                ds.Tables[1].TableName = "Media";
                ds.Tables[2].TableName = "Agency";
                ds.Tables[3].TableName = "Advertiser";
                ds.Tables[4].TableName = "Brand";
                ds.Tables[5].TableName = "Sector";
                ds.Tables[6].TableName = "SubSector";
                ds.Tables[7].TableName = "Category";
                ds.Tables[8].TableName = "Product";
                ds.Tables[9].TableName = "ProdVersion";
                // ds.Tables[10].TableName = "Program";

                HttpContext.Current.Cache.Insert("dsLookUpByUser_OD_" + AppUser.CurrUserID.ToString(), ds, null, DateTime.Now.AddMinutes(60), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);

                return ds;
            }
            else
            {
                return ((DataSet)(HttpContext.Current.Cache["dsLookUpByUser_OD_" + AppUser.CurrUserID.ToString()]));
            }
        }





        #region FillLists


        private void FillSectors()
        {
            DataTable dt = GetLookupDataSet().Tables[5];

            string filter = "1=1";
            switch (lstMediaType.SelectedValue)
            {
                case "1":
                    {
                        filter += " AND MediaType='TVCR' AND TV = 1";
                        break;
                    }

                case "3":
                    {
                        filter += " AND MediaType='TVCR'  AND RD = 1";
                        break;
                    }
                case "5":
                    {
                        filter += " AND MediaType='TVCR'  AND CB = 1";
                        break;
                    }
                case "6":
                    {
                        filter += " AND MediaType='PR'  AND PR = 1";
                        break;
                    }
                case "7":
                    {
                        filter += " AND MediaType='OD'  AND OD = 1";
                        break;
                    }
                case "8":
                    {
                        filter += " AND MediaType='NS'  AND NS = 1";
                        break;
                    }

            }
            string sort = "SectorName";

            DataView dv = new DataView(dt, filter, sort,
                                       DataViewRowState.OriginalRows);
            DataTable dtcolumns = dv.ToTable(true, "SectorID", "SectorName");

            if (dtcolumns.Rows.Count > 0)
            {
                dtcolumns = RemoveDuplicateRows(dtcolumns, "SectorName");
                lstSector.DataSource = dtcolumns;
                lstSector.DataBind();
            }



            lstSector.Items.Insert(0, new ListItem("- ALL -", "0"));
        }


        public DataTable RemoveDuplicateRows(DataTable dTable, string colName)
        {
            Hashtable hTable = new Hashtable();
            ArrayList duplicateList = new ArrayList();

            //Add list of all the unique item value to hashtable, which stores combination of key, value pair.
            //And add duplicate item value in arraylist.
            foreach (DataRow drow in dTable.Rows)
            {
                if (hTable.Contains(drow[colName]))
                    duplicateList.Add(drow);
                else
                    hTable.Add(drow[colName], string.Empty);
            }

            //Removing a list of duplicate items from datatable.
            foreach (DataRow dRow in duplicateList)
                dTable.Rows.Remove(dRow);

            //Datatable which contains unique records will be return as output.
            return dTable;
        }


        private void FillSubSectors()
        {
            DataTable dt = GetLookupDataSet().Tables[6];

            string filter = "1=1";
            switch (lstMediaType.SelectedValue)
            {
                case "1":
                    {
                        filter += " AND MediaType='TVCR' AND TV = 1";
                        break;
                    }

                case "3":
                    {
                        filter += " AND MediaType='TVCR'  AND RD = 1";
                        break;
                    }
                case "5":
                    {
                        filter += " AND MediaType='TVCR'  AND CB = 1";
                        break;
                    }
                case "6":
                    {
                        filter += " AND MediaType='PR'  AND PR = 1";
                        break;
                    }
                case "7":
                    {
                        filter += " AND MediaType='OD'  AND OD = 1";
                        break;
                    }
                case "8":
                    {
                        filter += " AND MediaType='NS'  AND NS = 1";
                        break;
                    }

            }

            filter += lstSector.SelectedValue != "0" ? " AND SectorID=" + lstSector.SelectedValue : "";

            string sort = "SubSectorName";

            DataView dv = new DataView(dt, filter, sort, DataViewRowState.OriginalRows);

            DataTable dtcolumns = dv.ToTable(true, "SubSectorID", "SubSectorName");

            if (dtcolumns.Rows.Count > 0)
            {
                dtcolumns = RemoveDuplicateRows(dtcolumns, "SubSectorName");

                lstSubSector.DataSource = dtcolumns;
                lstSubSector.DataBind();

                lstSubSector2.DataSource = dtcolumns;
                lstSubSector2.DataBind();
            }

            lstSubSector.Items.Insert(0, new ListItem("- ALL -", "0"));
            lstSubSector2.Items.Insert(0, new ListItem("- ALL -", "0"));
        }

        private void FillCategories()
        {
            DataTable dt = GetLookupDataSet().Tables[7];

            string filter = "1=1";
            switch (lstMediaType.SelectedValue)
            {
                case "1":
                    {
                        filter += " AND MediaType='TVCR' AND TV = 1";
                        break;
                    }

                case "3":
                    {
                        filter += " AND MediaType='TVCR'  AND RD = 1";
                        break;
                    }
                case "5":
                    {
                        filter += " AND MediaType='TVCR'  AND CB = 1";
                        break;
                    }
                case "6":
                    {
                        filter += " AND MediaType='PR'  AND PR = 1";
                        break;
                    }
                case "7":
                    {
                        filter += " AND MediaType='OD'  AND OD = 1";
                        break;
                    }
                case "8":
                    {
                        filter += " AND MediaType='NS'  AND NS = 1";
                        break;
                    }

            }

            filter += lstSector.SelectedValue != "0" ? " AND SectorID=" + lstSector.SelectedValue : "";
            filter += lstSubSector.SelectedValue != "0" ? " AND SubSectorID=" + lstSubSector.SelectedValue : "";

            string sort = "CategoryName";

            DataView dv = new DataView(dt, filter, sort, DataViewRowState.OriginalRows);

            DataTable dtcolumns = dv.ToTable(true, "CategoryID", "CategoryName");

            if (dtcolumns.Rows.Count > 0)
            {
                dtcolumns = RemoveDuplicateRows(dtcolumns, "CategoryName");
                lstCategory.DataSource = dtcolumns;
                lstCategory.DataBind();
            }

            lstCategory.Items.Insert(0, new ListItem("- ALL -", "0"));
        }

        private void FillAdvertisers()
        {
            DataTable dt = GetLookupDataSet().Tables[3];

            string filter = "1=1";
            switch (lstMediaType.SelectedValue)
            {
                case "1":
                    {
                        filter += " AND MediaType='TVCR' AND TV = 1";
                        break;
                    }

                case "3":
                    {
                        filter += " AND MediaType='TVCR'  AND RD = 1";
                        break;
                    }
                case "5":
                    {
                        filter += " AND MediaType='TVCR'  AND CB = 1";
                        break;
                    }
                case "6":
                    {
                        filter += " AND MediaType='PR'  AND PR = 1";
                        break;
                    }
                case "7":
                    {
                        filter += " AND MediaType='OD'  AND OD = 1";
                        break;
                    }
                case "8":
                    {
                        filter += " AND MediaType='NS'  AND NS = 1";
                        break;
                    }

            }

            string sort = "AdvertiserName";

            DataView dv = new DataView(dt, filter, sort, DataViewRowState.OriginalRows);

            lstAdvertiser.DataSource = dv;
            lstAdvertiser.DataBind();

            lstAdvertiser.Items.Insert(0, new ListItem("- ALL -", "0"));
        }

        private void FillAgencies()
        {
            DataTable dt = GetLookupDataSet().Tables[2];

            string filter = "1=1";
            switch (lstMediaType.SelectedValue)
            {
                case "1":
                    {
                        filter += " AND MediaType='TVCR' AND TV = 1";
                        break;
                    }

                case "3":
                    {
                        filter += " AND MediaType='TVCR'  AND RD = 1";
                        break;
                    }
                case "5":
                    {
                        filter += " AND MediaType='TVCR'  AND CB = 1";
                        break;
                    }
                case "6":
                    {
                        filter += " AND MediaType='PR'  AND PR = 1";
                        break;
                    }
                case "7":
                    {
                        filter += " AND MediaType='OD'  AND OD = 1";
                        break;
                    }
                case "8":
                    {
                        filter += " AND MediaType='NS'  AND NS = 1";
                        break;
                    }

            }
            string sort = "AgencyName";

            DataView dv = new DataView(dt, filter, sort, DataViewRowState.OriginalRows);

            lstAgency.DataSource = dv;
            lstAgency.DataBind();
            lstAgency.Items.Insert(0, new ListItem("- ALL -", "0"));
        }

        protected void lstSector_Changed(object sender, EventArgs e)
        {
            FillSubSectors();
            FillCategories();

        }

        protected void lstSubSector_Changed(object sender, EventArgs e)
        {
            FillCategories();

        }

        #endregion


        #region Fill Media

        private void FillMediaTypes()
        {

            lstMediaType.DataSource = GetLookupDataSet().Tables["MediaType"];
            lstMediaType.DataBind();


            FillMedia(Utility.ToInt(lstMediaType.SelectedValue));
        }

        private void FillMedia(int MediaTypeCode)
        {
            if (MediaTypeCode == 10) // Planning
            {
                BindPlanningMediaCodes();
            }
            else
            {
                if (MediaTypeCode > 0)
                    lstMedia.DataSource = new DataView(GetLookupDataSet().Tables["Media"], "MediaTypeCode=" + MediaTypeCode.ToString(), "MediaName", DataViewRowState.OriginalRows);
                else
                    lstMedia.DataSource = GetLookupDataSet().Tables["Media"];


                lstMedia.DataBind();

                //lstMedia.Items.Insert(0, new ListItem("All", "0"));

                //Utility.SelectListItemByText(lstMedia, "TV"); 
            }
        }

        private void BindPlanningMediaCodes()
        {
            DataTable dt = RfController.GetPlanningMediaCodes();
            if (dt.Rows.Count > 0)
            {
                lstMedia.DataSource = dt;
                lstMedia.DataBind();
            }
            else
            {
                lstMedia.ClearSelection();
                lstMedia.DataSource = null;
                lstMedia.DataBind();
            }
        }
        protected void lstMedia_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        //void txtBillboardQuantity_TextChanged(object sender, EventArgs e)
        //{

        //}

        protected void lstMediaType_SelectedIndexChanged(object sender, EventArgs e)
        {



            if (lstMediaType.SelectedValue == "10") //means Planning
            {
                calS.SpecialDays.Clear();
                calE.SpecialDays.Clear();
                pnlmsg.Visible = false;

                RowAgency.Visible = false;
                RowVersion.Visible = false;
                RowOptionStartTime.Visible = false;
                RowSize.Visible = false;
                RowQuality.Visible = false;
                RowTypeofAds.Visible = false;
                RowPriceFrom.Visible = false;
                RowReportFields.Visible = false;
                RowDownLoadAll.Visible = false;
                //  RowNegotiatedPrice.Visible = true;
                chkAllMedia.Visible = false;
                dvMediaList.Visible = true;
                //HideforPlanning.Visible = false;
                btnSearchMap.Visible = false;
                FillMedia(Utility.ToInt(lstMediaType.SelectedValue));
                btnSearch1.Text = "Run";
                btnSearchMap1.Visible = false;
                drpAvenueCOunt.Visible = true;

            }
            else //outdoor
            {
                drpAvenueCOunt.Visible = false;
                btnSearchMap1.Visible = true;
                btnSearch1.Text = "Search";
                SetCalendarDates();
                pnlmsg.Visible = true;
                // HideforPlanning.Visible = true;
                // btnSearchMap.Visible = true;
                RowAgency.Visible = true;
                RowVersion.Visible = true;
                RowOptionStartTime.Visible = true;
                RowSize.Visible = true;
                RowQuality.Visible = true;
                RowTypeofAds.Visible = true;
                RowPriceFrom.Visible = true;
                RowReportFields.Visible = true;
                RowDownLoadAll.Visible = true;
                chkAllMedia.Visible = true;
                chkAllMedia.Checked = true;
                dvMediaList.Visible = false;
                RowNegotiatedPrice.Visible = false;
                FillMedia(Utility.ToInt(lstMediaType.SelectedValue));

                FillAdvertisers();

            }

        }



        #endregion



        #region AutoComplete Functions



        [WebMethod]
        public static string[] AutoComplete_FillBrand(string prefixText, int count)
        {
            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[4];

            DataRow[] drs = dt.Select("BrandName LIKE '%" + prefixText + "%'");

            DataRow[] drsUserWrite = dt.Select("BrandName = '" + prefixText + "'");

            try
            {
                if (drsUserWrite.Length == 1) //If user write and that item is in database
                {
                    HttpContext.Current.Session["OUTDOORUserWriteProductName"] = drsUserWrite[0][0];
                    HttpContext.Current.Session["OUTDOORUserWriteProductNameText"] = drsUserWrite[0][2];
                }
                else
                {
                    HttpContext.Current.Session["OUTDOORUserWriteProductName"] = -1;
                    HttpContext.Current.Session["OUTDOORUserWriteProductNameText"] = "";
                }
            }
            catch { }


            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["BrandName"].ToString(), dr["BrandID"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }

        [WebMethod]
        public static string[] AutoComplete_FillProduct(string prefixText, int count, string contextKey)
        {
            //contextKey is brandCode


            string filter = "ProductName LIKE '%" + prefixText + "%'";

            //get brand 

            if (contextKey != null && contextKey != "" && contextKey != "0")
            {
                filter += " AND BrandID = " + contextKey;
            }

            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[8];

            DataRow[] drs = dt.Select(filter);

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["ProductName"].ToString(), dr["ProductID"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }


        [WebMethod]
        public static string[] AutoComplete_FillVersion(string prefixText, int count, string contextKey)
        {
            //contextKey is brandCode


            string filter = "ProdVersionName LIKE '%" + prefixText + "%'";
            string filterwrite = "ProdVersionName = '" + prefixText + "'";

            //get brand 

            //if (contextKey != null && contextKey != "" && contextKey != "0")
            //{
            //}

            if (count == 0) { count = 10; }
            List<string> items = new List<string>(count);

            DataTable dt = GetLookupDataSet().Tables[9];

            DataRow[] drsUserWrite = dt.Select(filterwrite);
            try
            {
                if (drsUserWrite.Length == 1) //If user write and that item is in database
                {
                    HttpContext.Current.Session["OUTDOORVerUserWriteProductName"] = drsUserWrite[0][0];
                    HttpContext.Current.Session["OUTDOORVerUserWriteProductNameText"] = drsUserWrite[0][2];

                }
                else
                {
                    HttpContext.Current.Session["OUTDOORVerUserWriteProductName"] = -1;
                    HttpContext.Current.Session["OUTDOORVerUserWriteProductNameText"] = "";
                }
            }
            catch { }


            DataRow[] drs = dt.Select(filter);

            int counter = 0;
            foreach (DataRow dr in drs)
            {
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["ProdVersionName"].ToString(), dr["ProdVersionID"].ToString()));


                if (++counter >= count) { break; }
            }

            return items.ToArray();
        }




        #endregion





        #region Fill Sector SubSector Category



        #endregion




        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            //bool tmp1;
            //bool tmp2;
            //string reportUrl = String.Empty;
            //tmp1 = DateTime.TryParse(calS.SelectedDate.ToShortDateString(), out sDate);
            //tmp2 = DateTime.TryParse(calE.SelectedDate.ToShortDateString(), out eDate);

            //if (sDate < Utility.ToDateTime("01/01/2000"))
            //    sDate = Utility.ToDateTime("01/01/2000");

            //if (eDate < Utility.ToDateTime("01/01/2000"))
            //    eDate = Utility.ToDateTime("01/01/2000");


            //mediaTypeCode = Utility.ToInt(lstMediaType.SelectedValue);

            //Session["SearchMediaCodes_outdoor"] = "";
            //foreach (ListItem itm in lstMedia.Items)
            //{
            //    if (itm.Selected)
            //        mediaCodes += itm.Value + ",";
            //}
            //mediaCodes = mediaCodes.TrimEnd(',');
            //Session["SearchMediaCodes_outdoor"] = mediaCodes;

            //String mediaCodesText = String.Empty;
            //Session["planningText"] = "";
            //foreach (ListItem itm in lstMedia.Items)
            //{
            //    if (itm.Selected)
            //        mediaCodesText += itm.Text + ",";
            //}
            //mediaCodesText = mediaCodesText.TrimEnd(',');
            //Session["planningText"] = mediaCodesText;

            //string SelectedMediaCodeToSend = string.Empty;
            //ArrayList arrSelectedAvenueToSend = new ArrayList();

            //foreach (ListItem listitem in lstMedia.Items)
            //{
            //    if (listitem.Selected)
            //    {
            //        SelectedMediaCodeToSend += listitem.Value + ",";
            //        arrSelectedAvenueToSend.Add(listitem.Text);
            //    }
            //}
            //SelectedMediaCodeToSend = SelectedMediaCodeToSend.TrimEnd(',');

            //TextBox txtBrandNEw = (TextBox)acBrand.FindControl("tbAutoComplete");
            //if (Utility.ToInt(acBrand.SelectedValue) == 0) //not selected by user
            //{
            //    try
            //    {
            //        if (Convert.ToInt32(Session["OUTDOORUserWriteProductName"].ToString()) != 0)
            //        {

            //            brandCode = Utility.ToInt(Session["OUTDOORUserWriteProductName"].ToString());
            //            product = Session["OUTDOORUserWriteProductNameText"].ToString();
            //        }
            //    }
            //    catch { }

            //}
            //else
            //{
            //    brandCode = Utility.ToInt(acBrand.SelectedValue);
            //    // TextBox txtBrand = (TextBox)acBrand.FindControl("tbAutoComplete");
            //    product = txtBrandNEw.Text;
            //}
            //product = txtBrandNEw.Text;
            //string vallCarr = string.Empty;
            //string vallBillBoardQuant = string.Empty;
            //string vallBillBoardType = string.Empty;

            //if (lstMediaType.SelectedValue == "10") //Planning
            //{

            //    ArrayList arrFetchCarriers = (ArrayList)ViewState["ArrayListCarriers"];
            //    ArrayList arrFetchBillBoardQuantity = (ArrayList)ViewState["ArrayListBillBoardQuantity"];
            //    ArrayList arrFetchBillboardType = (ArrayList)ViewState["ArrayListBillboardType"];
            //    ArrayList arrFetchNegotiatedPrice = (ArrayList)ViewState["ArrayListNegotiatedPrice"];

            //    ArrayList arrCarrToSend = new ArrayList();
            //    ArrayList arrBilBrdQuantToSend = new ArrayList();
            //    ArrayList arrBilBrdTypeToSend = new ArrayList();
            //    ArrayList arrNegotiatedPriceToSend = new ArrayList();


            //    ArrayList arrFetchExceptionalCaseAvenueName = (ArrayList)ViewState["arrExceptionalCaseAvenueName"];
            //    ArrayList arrFetchExceptionalCaseAverageVehicle = (ArrayList)ViewState["arrExceptionalCaseAverageVehicle"];
            //    ArrayList arrFetchExceptionalCaseBillBoardQuant = (ArrayList)ViewState["arrExceptionalCaseBillBoardQuant"];
            //    ArrayList arrFetchExceptionalCaseCarrier = (ArrayList)ViewState["arrExceptionalCaseCarrier"];
            //    ArrayList arrFetchExceptionalCaseBillBoardType = (ArrayList)ViewState["arrExceptionalCaseBillBoardType"];
            //    ArrayList arrFetchExceptionalCaseNegoPrice = (ArrayList)ViewState["arrExceptionalCaseNegoPrice"];

            //    ArrayList arrExceptionalCaseAvenueNameToSend = new ArrayList();
            //    ArrayList arrExceptionalCaseAverageVehicleToSend = new ArrayList();
            //    ArrayList arrExceptionalCaseBillBoardQuantToSend = new ArrayList();
            //    ArrayList arrExceptionalCaseCarrierToSend = new ArrayList();
            //    ArrayList arrExceptionalCaseBillBoardTypeToSend = new ArrayList();
            //    ArrayList arrExceptionalCaseNegoPriceToSend = new ArrayList();

            //    if (arrFetchCarriers != null)
            //    {
            //        for (int i = 0; i < arrFetchCarriers.Count; i++)
            //        {
            //            DropDownList drpCarriers = (DropDownList)(arrFetchCarriers[i]);
            //            DropDownList drpBillBoardType = (DropDownList)(arrFetchBillboardType[i]);
            //            TextBox txtBillBoardQuant = (TextBox)(arrFetchBillBoardQuantity[i]);
            //            TextBox txtNegoPrice = (TextBox)(arrFetchNegotiatedPrice[i]);

            //            vallCarr = drpCarriers.Text.ToString();
            //            vallBillBoardType = drpBillBoardType.Text.ToString();
            //            vallBillBoardQuant = txtBillBoardQuant.Text;

            //            arrCarrToSend.Add(vallCarr);
            //            arrBilBrdQuantToSend.Add(vallBillBoardQuant);
            //            arrBilBrdTypeToSend.Add(vallBillBoardType);
            //            arrNegotiatedPriceToSend.Add(txtNegoPrice.Text);

            //        }
            //        Session["SelectedAvenuesCarrier"] = arrCarrToSend;
            //        Session["SelectedAvenuesBillBoardType"] = arrBilBrdTypeToSend;
            //        Session["SelectedAvenuesBillBoardQuant"] = arrBilBrdQuantToSend;
            //        Session["SelectedAvenueToSend"] = arrSelectedAvenueToSend;
            //        Session["SelectedNegoPrice"] = arrNegotiatedPriceToSend;

            //    }
            //    if (arrFetchExceptionalCaseAvenueName != null)
            //    {
            //        for (int i = 0; i < arrFetchExceptionalCaseAvenueName.Count; i++)
            //        {
            //            TextBox txtExcAveName = (TextBox)(arrFetchExceptionalCaseAvenueName[i]);
            //            arrExceptionalCaseAvenueNameToSend.Add(txtExcAveName.Text);

            //            TextBox txtExcAvgVeh = (TextBox)(arrFetchExceptionalCaseAverageVehicle[i]);
            //            arrExceptionalCaseAverageVehicleToSend.Add(txtExcAvgVeh.Text);

            //            TextBox txtExcBillBrdQua = (TextBox)(arrFetchExceptionalCaseBillBoardQuant[i]);
            //            arrExceptionalCaseBillBoardQuantToSend.Add(txtExcBillBrdQua.Text);

            //            TextBox txtExcCarr = (TextBox)(arrFetchExceptionalCaseCarrier[i]);
            //            arrExceptionalCaseCarrierToSend.Add(txtExcCarr.Text);

            //            TextBox txtExcBillBrdTyp = (TextBox)(arrFetchExceptionalCaseBillBoardType[i]);
            //            arrExceptionalCaseBillBoardTypeToSend.Add(txtExcBillBrdTyp.Text);

            //            TextBox txtExcNegPrce = (TextBox)(arrFetchExceptionalCaseNegoPrice[i]);
            //            arrExceptionalCaseNegoPriceToSend.Add(txtExcNegPrce.Text);
            //        }
            //        Session["ExceptionalCaseAvenueName"] = arrExceptionalCaseAvenueNameToSend;
            //        Session["ExceptionalCaseAverageVehicle"] = arrExceptionalCaseAverageVehicleToSend;
            //        Session["ExceptionalCaseBillBoardQuantity"] = arrExceptionalCaseBillBoardQuantToSend;
            //        Session["ExceptionalCaseCarrier"] = arrExceptionalCaseCarrierToSend;
            //        Session["ExceptionalCaseBillBoardType"] = arrExceptionalCaseBillBoardTypeToSend;
            //        Session["ExceptionalCaseNegoPrice"] = arrExceptionalCaseNegoPriceToSend;

            //    }
            //    //if (product == "")
            //    //{
            //    //    AjaxFuncs.MsgBox(this.Page,
            //    //                     "Please choose the valid product.");
            //    //    return;
            //    //}
            //    reportUrl = "report-outdoorplanning.aspx";
            //    Response.Redirect(
            //        Server.UrlPathEncode(
            //            string.Format(
            //                reportUrl + "?sd={0}&ed={1}&mtc={2}&mc={3}&smc={4}&adv={5}&s={6}&ss={7}&cc={8}&np={9}&product={10}",
            //                sDate.ToShortDateString().Replace("/", "_"), eDate.ToShortDateString().Replace("/", "_"), mediaTypeCode, chkAllMedia.Checked,
            //                SelectedMediaCodeToSend, lstAdvertiser.SelectedItem.ToString(), lstSector.SelectedItem.ToString(),
            //                lstSubSector.SelectedItem.ToString(), lstCategory.SelectedItem.ToString(), txtnEGOTIATEDpRICE.Text.ToString(), product)));


            //}
            //else //Outdoor
            //{
            //    DownloadOnly = chkDownload.Checked;
            //    if (DownloadOnly && (lstCategory.SelectedItem.Text == "- ALL -"))
            //    {
            //        AjaxFuncs.MsgBox(this.Page,
            //                         "To download all the videos, audios, or images related to your category, u must select the category.");
            //        return;
            //    }

            //    DownloadOnlyAdvertiser = chkDownloadAdvertiser.Checked;
            //    if (DownloadOnlyAdvertiser && (lstAdvertiser.SelectedItem.Text == "- ALL -"))
            //    {
            //        AjaxFuncs.MsgBox(this.Page,
            //                         "To download all the videos, audios, or images related to your advertiser, u must select the advertiser.");
            //        return;
            //    }




            //    programCode = 0;

            //    sectorCode = Utility.ToInt(lstSector.SelectedValue);
            //    subSectorCode = Utility.ToInt(lstSubSector.SelectedValue);

            //    categoryCode = Utility.ToInt(lstCategory.SelectedValue);

            //    advertiserCode = Utility.ToInt(lstAdvertiser.SelectedValue);


            //    sector = lstSector.SelectedItem.Text;
            //    subsector = lstSubSector.SelectedItem.Text;
            //    category = lstCategory.SelectedItem.Text;
            //    advertiser = lstAdvertiser.SelectedItem.Text;
            //    agency = lstAgency.SelectedItem.Text;

            //    //brandCode = Utility.ToInt(acBrand.SelectedValue);

            //    if (Utility.ToInt(acBrand.SelectedValue) == 0) //not selected by user
            //    {
            //        try
            //        {
            //            if (Convert.ToInt32(Session["OUTDOORUserWriteProductName"].ToString()) != 0)
            //            {

            //                brandCode = Utility.ToInt(Session["OUTDOORUserWriteProductName"].ToString());
            //                product = Session["OUTDOORUserWriteProductNameText"].ToString();
            //            }
            //        }
            //        catch { }

            //    }
            //    else
            //    {
            //        brandCode = Utility.ToInt(acBrand.SelectedValue);
            //        TextBox txtBrand = (TextBox)acBrand.FindControl("tbAutoComplete");
            //        product = txtBrand.Text;
            //    }


            //    DownloadOnlyProduct = chkDownloadProduct.Checked;
            //    if (DownloadOnlyProduct && (brandCode == 0))
            //    {
            //        AjaxFuncs.MsgBox(this.Page,
            //                         "To download all the videos, audios, or images related to your product, u must select the product.");
            //        return;
            //    }

            //    productCode = Utility.ToInt(acProduct.SelectedValue);
            //    //versionCode = Utility.ToInt(acVersion.SelectedValue);

            //    if (Utility.ToInt(acVersion.SelectedValue) == 0) //not selected by user
            //    {
            //        try
            //        {
            //            if (Convert.ToInt32(Session["OUTDOORVerUserWriteProductName"].ToString()) != 0)
            //            {

            //                versionCode = Utility.ToInt(Session["OUTDOORVerUserWriteProductName"].ToString());
            //                version = Session["OUTDOORVerUserWriteProductNameText"].ToString();
            //            }
            //        }
            //        catch { }

            //    }
            //    else
            //    {
            //        versionCode = Utility.ToInt(acVersion.SelectedValue);
            //        TextBox txtVersion = (TextBox)acVersion.FindControl("tbAutoComplete");
            //        version = txtVersion.Text;
            //    }


            //    agencyCode = Utility.ToInt(lstAgency.SelectedValue);

            //    sTime = Utility.ToInt(lstStartTime.SelectedValue);
            //    eTime = Utility.ToInt(lstEndTime.SelectedValue);

            //    quality = lstQuality.SelectedValue;
            //    size = Utility.ToInt(lstSize.SelectedValue);
            //    typeOfAds = Utility.ToInt(lstTypeOfAds.SelectedValue);

            //    sPrice = tbPriceFrom.Text != "" ? Utility.ToInt(tbPriceFrom.Text) : 0;
            //    ePrice = tbPriceTo.Text != "" ? Utility.ToInt(tbPriceTo.Text) : 0;

            //    firstAppearanceOnly = chkFirstAppearance.Checked;




            //    string cols = "";

            //    foreach (ListItem itm in lstFields.Items)
            //    {
            //        if (itm.Selected)
            //        {
            //            cols += itm.Value + ", ";
            //        }
            //    }

            //    if (cols.Contains(","))
            //        cols = cols.Substring(0, cols.LastIndexOf(","));



            //    reportUrl = "";
            //    if (((ImageButton)sender).ID == "btnSearchMap")
            //    {
            //        reportUrl = "report-outdoor-map.aspx";
            //    }
            //    else
            //    {
            //        reportUrl = "report-outdoor.aspx";
            //    }

            //    Response.Redirect(
            //          Server.UrlPathEncode(
            //              string.Format(
            //                  reportUrl + "?sd={0}&ed={1}&mtc={2}&mc={3}&s={4}&ss={5}&cc={6}&adv={7}&brnd={8}&prod={9}&ver={10}&agn={11}&st={12}&et={13}&sp={14}&ep={15}&size={16}&quality={17}&typeOfads={18}&fa={19}&cols={20}&down={21}&zs={22}&zss={23}&zc={24}&zad={25}&zag={26}&zp={27}&zve={28}&downpro={29}&downadv={30}",
            //                  sDate.ToShortDateString().Replace("/", "_"), eDate.ToShortDateString().Replace("/", "_"),
            //                  mediaTypeCode, chkAllMedia.Checked, sectorCode, subSectorCode, categoryCode, advertiserCode,
            //                  brandCode, productCode, versionCode, agencyCode, sTime, eTime, sPrice, ePrice, size, quality,
            //                  typeOfAds, firstAppearanceOnly, cols, DownloadOnly, sector, subsector, category, advertiser, agency, product, version, DownloadOnlyProduct, DownloadOnlyAdvertiser)));
            //}
        }



        protected void btnSearchMap_Click(object sender, EventArgs e)
        {

        }

        protected void chkAllMedia_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAllMedia.Checked)
                dvMediaList.Visible = false;
            else
                dvMediaList.Visible = true;
        }

        protected void drpAvenueCOunt_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnSearch1_Click(object sender, EventArgs e)
        {
            bool tmp1;
            bool tmp2;
            string reportUrl = String.Empty;
            tmp1 = DateTime.TryParse(calS.SelectedDate.ToShortDateString(), out sDate);
            tmp2 = DateTime.TryParse(calE.SelectedDate.ToShortDateString(), out eDate);

            if (sDate < Utility.ToDateTime("01/01/2000"))
                sDate = Utility.ToDateTime("01/01/2000");

            if (eDate < Utility.ToDateTime("01/01/2000"))
                eDate = Utility.ToDateTime("01/01/2000");


            mediaTypeCode = Utility.ToInt(lstMediaType.SelectedValue);

            Session["SearchMediaCodes_outdoor"] = "";
            foreach (ListItem itm in lstMedia.Items)
            {
                if (itm.Selected)
                    mediaCodes += itm.Value + ",";
            }
            mediaCodes = mediaCodes.TrimEnd(',');
            Session["SearchMediaCodes_outdoor"] = mediaCodes;

            String mediaCodesText = String.Empty;
            Session["planningText"] = "";
            foreach (ListItem itm in lstMedia.Items)
            {
                if (itm.Selected)
                    mediaCodesText += itm.Text + ",";
            }
            mediaCodesText = mediaCodesText.TrimEnd(',');
            Session["planningText"] = mediaCodesText;

            string SelectedMediaCodeToSend = string.Empty;
            ArrayList arrSelectedAvenueToSend = new ArrayList();

            foreach (ListItem listitem in lstMedia.Items)
            {
                if (listitem.Selected)
                {
                    SelectedMediaCodeToSend += listitem.Value + ",";
                    arrSelectedAvenueToSend.Add(listitem.Text);
                }
            }
            SelectedMediaCodeToSend = SelectedMediaCodeToSend.TrimEnd(',');

            TextBox txtBrandNEw = (TextBox)acBrand.FindControl("tbAutoComplete");
            if (Utility.ToInt(acBrand.SelectedValue) == 0) //not selected by user
            {
                try
                {
                    if (Convert.ToInt32(Session["OUTDOORUserWriteProductName"].ToString()) != 0)
                    {

                        brandCode = Utility.ToInt(Session["OUTDOORUserWriteProductName"].ToString());
                        product = Session["OUTDOORUserWriteProductNameText"].ToString();
                    }
                }
                catch { }

            }
            else
            {
                brandCode = Utility.ToInt(acBrand.SelectedValue);
                // TextBox txtBrand = (TextBox)acBrand.FindControl("tbAutoComplete");
                product = txtBrandNEw.Text;
            }
            product = txtBrandNEw.Text;
            string vallCarr = string.Empty;
            string vallBillBoardQuant = string.Empty;
            string vallBillBoardType = string.Empty;

            if (lstMediaType.SelectedValue == "10") //Planning
            {

                ArrayList arrFetchCarriers = (ArrayList)ViewState["ArrayListCarriers"];
                ArrayList arrFetchBillBoardQuantity = (ArrayList)ViewState["ArrayListBillBoardQuantity"];
                ArrayList arrFetchBillboardType = (ArrayList)ViewState["ArrayListBillboardType"];
                ArrayList arrFetchNegotiatedPrice = (ArrayList)ViewState["ArrayListNegotiatedPrice"];

                ArrayList arrCarrToSend = new ArrayList();
                ArrayList arrBilBrdQuantToSend = new ArrayList();
                ArrayList arrBilBrdTypeToSend = new ArrayList();
                ArrayList arrNegotiatedPriceToSend = new ArrayList();


                ArrayList arrFetchExceptionalCaseAvenueName = (ArrayList)ViewState["arrExceptionalCaseAvenueName"];
                ArrayList arrFetchExceptionalCaseAverageVehicle = (ArrayList)ViewState["arrExceptionalCaseAverageVehicle"];
                ArrayList arrFetchExceptionalCaseBillBoardQuant = (ArrayList)ViewState["arrExceptionalCaseBillBoardQuant"];
                ArrayList arrFetchExceptionalCaseCarrier = (ArrayList)ViewState["arrExceptionalCaseCarrier"];
                ArrayList arrFetchExceptionalCaseBillBoardType = (ArrayList)ViewState["arrExceptionalCaseBillBoardType"];
                ArrayList arrFetchExceptionalCaseNegoPrice = (ArrayList)ViewState["arrExceptionalCaseNegoPrice"];

                ArrayList arrExceptionalCaseAvenueNameToSend = new ArrayList();
                ArrayList arrExceptionalCaseAverageVehicleToSend = new ArrayList();
                ArrayList arrExceptionalCaseBillBoardQuantToSend = new ArrayList();
                ArrayList arrExceptionalCaseCarrierToSend = new ArrayList();
                ArrayList arrExceptionalCaseBillBoardTypeToSend = new ArrayList();
                ArrayList arrExceptionalCaseNegoPriceToSend = new ArrayList();

                if (arrFetchCarriers != null)
                {
                    for (int i = 0; i < arrFetchCarriers.Count; i++)
                    {
                        DropDownList drpCarriers = (DropDownList)(arrFetchCarriers[i]);
                        DropDownList drpBillBoardType = (DropDownList)(arrFetchBillboardType[i]);
                        TextBox txtBillBoardQuant = (TextBox)(arrFetchBillBoardQuantity[i]);
                        TextBox txtNegoPrice = (TextBox)(arrFetchNegotiatedPrice[i]);

                        vallCarr = drpCarriers.Text.ToString();
                        vallBillBoardType = drpBillBoardType.Text.ToString();
                        vallBillBoardQuant = txtBillBoardQuant.Text;

                        arrCarrToSend.Add(vallCarr);
                        arrBilBrdQuantToSend.Add(vallBillBoardQuant);
                        arrBilBrdTypeToSend.Add(vallBillBoardType);
                        arrNegotiatedPriceToSend.Add(txtNegoPrice.Text);

                    }
                    Session["SelectedAvenuesCarrier"] = arrCarrToSend;
                    Session["SelectedAvenuesBillBoardType"] = arrBilBrdTypeToSend;
                    Session["SelectedAvenuesBillBoardQuant"] = arrBilBrdQuantToSend;
                    Session["SelectedAvenueToSend"] = arrSelectedAvenueToSend;
                    Session["SelectedNegoPrice"] = arrNegotiatedPriceToSend;

                }
                if (arrFetchExceptionalCaseAvenueName != null)
                {
                    for (int i = 0; i < arrFetchExceptionalCaseAvenueName.Count; i++)
                    {
                        TextBox txtExcAveName = (TextBox)(arrFetchExceptionalCaseAvenueName[i]);
                        arrExceptionalCaseAvenueNameToSend.Add(txtExcAveName.Text);

                        TextBox txtExcAvgVeh = (TextBox)(arrFetchExceptionalCaseAverageVehicle[i]);
                        arrExceptionalCaseAverageVehicleToSend.Add(txtExcAvgVeh.Text);

                        TextBox txtExcBillBrdQua = (TextBox)(arrFetchExceptionalCaseBillBoardQuant[i]);
                        arrExceptionalCaseBillBoardQuantToSend.Add(txtExcBillBrdQua.Text);

                        TextBox txtExcCarr = (TextBox)(arrFetchExceptionalCaseCarrier[i]);
                        arrExceptionalCaseCarrierToSend.Add(txtExcCarr.Text);

                        TextBox txtExcBillBrdTyp = (TextBox)(arrFetchExceptionalCaseBillBoardType[i]);
                        arrExceptionalCaseBillBoardTypeToSend.Add(txtExcBillBrdTyp.Text);

                        TextBox txtExcNegPrce = (TextBox)(arrFetchExceptionalCaseNegoPrice[i]);
                        arrExceptionalCaseNegoPriceToSend.Add(txtExcNegPrce.Text);
                    }
                    Session["ExceptionalCaseAvenueName"] = arrExceptionalCaseAvenueNameToSend;
                    Session["ExceptionalCaseAverageVehicle"] = arrExceptionalCaseAverageVehicleToSend;
                    Session["ExceptionalCaseBillBoardQuantity"] = arrExceptionalCaseBillBoardQuantToSend;
                    Session["ExceptionalCaseCarrier"] = arrExceptionalCaseCarrierToSend;
                    Session["ExceptionalCaseBillBoardType"] = arrExceptionalCaseBillBoardTypeToSend;
                    Session["ExceptionalCaseNegoPrice"] = arrExceptionalCaseNegoPriceToSend;

                }
                //if (product == "")
                //{
                //    AjaxFuncs.MsgBox(this.Page,
                //                     "Please choose the valid product.");
                //    return;
                //}
                reportUrl = "report-outdoorplanning.aspx";
                Response.Redirect(
                    Server.UrlPathEncode(
                        string.Format(
                            reportUrl + "?sd={0}&ed={1}&mtc={2}&mc={3}&smc={4}&adv={5}&s={6}&ss={7}&cc={8}&np={9}&product={10}",
                            sDate.ToShortDateString().Replace("/", "_"), eDate.ToShortDateString().Replace("/", "_"), mediaTypeCode, chkAllMedia.Checked,
                            SelectedMediaCodeToSend, lstAdvertiser.SelectedItem.ToString(), lstSector.SelectedItem.ToString(),
                            lstSubSector.SelectedItem.ToString(), lstCategory.SelectedItem.ToString(), txtnEGOTIATEDpRICE.Text.ToString(), product)));


            }
            else //Outdoor
            {
                DownloadOnly = chkDownload.Checked;
                if (DownloadOnly && (lstCategory.SelectedItem.Text == "- ALL -"))
                {
                    AjaxFuncs.MsgBox(this.Page,
                                     "To download all the videos, audios, or images related to your category, u must select the category.");
                    return;
                }

                DownloadOnlyAdvertiser = chkDownloadAdvertiser.Checked;
                if (DownloadOnlyAdvertiser && (lstAdvertiser.SelectedItem.Text == "- ALL -"))
                {
                    AjaxFuncs.MsgBox(this.Page,
                                     "To download all the videos, audios, or images related to your advertiser, u must select the advertiser.");
                    return;
                }




                programCode = 0;

                sectorCode = Utility.ToInt(lstSector.SelectedValue);
                subSectorCode = Utility.ToInt(lstSubSector.SelectedValue);

                categoryCode = Utility.ToInt(lstCategory.SelectedValue);

                advertiserCode = Utility.ToInt(lstAdvertiser.SelectedValue);


                sector = lstSector.SelectedItem.Text;
                subsector = lstSubSector.SelectedItem.Text;
                category = lstCategory.SelectedItem.Text;
                advertiser = lstAdvertiser.SelectedItem.Text;
                agency = lstAgency.SelectedItem.Text;

                //brandCode = Utility.ToInt(acBrand.SelectedValue);

                if (Utility.ToInt(acBrand.SelectedValue) == 0) //not selected by user
                {
                    try
                    {
                        if (Convert.ToInt32(Session["OUTDOORUserWriteProductName"].ToString()) != 0)
                        {

                            brandCode = Utility.ToInt(Session["OUTDOORUserWriteProductName"].ToString());
                            product = Session["OUTDOORUserWriteProductNameText"].ToString();
                        }
                    }
                    catch { }

                }
                else
                {
                    brandCode = Utility.ToInt(acBrand.SelectedValue);
                    TextBox txtBrand = (TextBox)acBrand.FindControl("tbAutoComplete");
                    product = txtBrand.Text;
                }


                DownloadOnlyProduct = chkDownloadProduct.Checked;
                if (DownloadOnlyProduct && (brandCode == 0))
                {
                    AjaxFuncs.MsgBox(this.Page,
                                     "To download all the videos, audios, or images related to your product, u must select the product.");
                    return;
                }

                productCode = Utility.ToInt(acProduct.SelectedValue);
                //versionCode = Utility.ToInt(acVersion.SelectedValue);

                if (Utility.ToInt(acVersion.SelectedValue) == 0) //not selected by user
                {
                    try
                    {
                        if (Convert.ToInt32(Session["OUTDOORVerUserWriteProductName"].ToString()) != 0)
                        {

                            versionCode = Utility.ToInt(Session["OUTDOORVerUserWriteProductName"].ToString());
                            version = Session["OUTDOORVerUserWriteProductNameText"].ToString();
                        }
                    }
                    catch { }

                }
                else
                {
                    versionCode = Utility.ToInt(acVersion.SelectedValue);
                    TextBox txtVersion = (TextBox)acVersion.FindControl("tbAutoComplete");
                    version = txtVersion.Text;
                }


                agencyCode = Utility.ToInt(lstAgency.SelectedValue);

                sTime = Utility.ToInt(lstStartTime.SelectedValue);
                eTime = Utility.ToInt(lstEndTime.SelectedValue);

                quality = lstQuality.SelectedValue;
                size = Utility.ToInt(lstSize.SelectedValue);
                typeOfAds = Utility.ToInt(lstTypeOfAds.SelectedValue);

                sPrice = tbPriceFrom.Text != "" ? Utility.ToInt(tbPriceFrom.Text) : 0;
                ePrice = tbPriceTo.Text != "" ? Utility.ToInt(tbPriceTo.Text) : 0;

                firstAppearanceOnly = chkFirstAppearance.Checked;




                string cols = "";

                foreach (ListItem itm in lstFields.Items)
                {
                    if (itm.Selected)
                    {
                        cols += itm.Value + ", ";
                    }
                }

                if (cols.Contains(","))
                    cols = cols.Substring(0, cols.LastIndexOf(","));



                reportUrl = "";
                if (((Button)sender).ID == "btnSearchMap1")
                {
                    reportUrl = "report-outdoor-map.aspx";
                }
                else
                {
                    reportUrl = "report-outdoor.aspx";
                }

                Response.Redirect(
                      Server.UrlPathEncode(
                          string.Format(
                              reportUrl + "?sd={0}&ed={1}&mtc={2}&mc={3}&s={4}&ss={5}&cc={6}&adv={7}&brnd={8}&prod={9}&ver={10}&agn={11}&st={12}&et={13}&sp={14}&ep={15}&size={16}&quality={17}&typeOfads={18}&fa={19}&cols={20}&down={21}&zs={22}&zss={23}&zc={24}&zad={25}&zag={26}&zp={27}&zve={28}&downpro={29}&downadv={30}",
                              sDate.ToShortDateString().Replace("/", "_"), eDate.ToShortDateString().Replace("/", "_"),
                              mediaTypeCode, chkAllMedia.Checked, sectorCode, subSectorCode, categoryCode, advertiserCode,
                              brandCode, productCode, versionCode, agencyCode, sTime, eTime, sPrice, ePrice, size, quality,
                              typeOfAds, firstAppearanceOnly, cols, DownloadOnly, sector, subsector, category, advertiser, agency, product, version, DownloadOnlyProduct, DownloadOnlyAdvertiser)));
            }
        }


    }
}